package com.korovyansk.mapsproto.ui;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;

import com.korovyansk.mapsproto.R;
import com.korovyansk.mapsproto.api.TilesCache;

public class MapActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.map);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = new MenuInflater(this);
		inflater.inflate(R.menu.map, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.menu_clear_cache:
			clearCache();
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	protected void clearCache(){
		TilesCache tilesCache = new TilesCache(this);
		final boolean success = tilesCache.clearCache();
		final int resId = success ? R.string.toast_cache_clear_ok : R.string.toast_cache_clear_fail;
		Toast.makeText(this, resId, Toast.LENGTH_SHORT).show();
	}
	
}